package com.java.elasticsearch.activemq.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Service;

import javax.jms.TextMessage;

/**
 * @author Woo_home
 * @create 2020/5/22 14:09
 */

@Service
public class SpringMQ_Consumer {

    @Autowired
    private JmsTemplate jmsTemplate;

    public static void main(String[] args){
        ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");

        // 相当于 new 一个 SpringMQ_Consumer，但是这里用的是 Spring，所以这里就不用 new 了
        SpringMQ_Consumer consumer = (SpringMQ_Consumer) ctx.getBean("springMQ_Consumer");

        String retValue  = (String) consumer.jmsTemplate.receiveAndConvert();

        System.out.println("****** 消费者收到消息 Topic : " + retValue);
    }
}
